//transmit support for std::string
//$Id: transmit_string.h 395 2010-03-26 14:01:03Z Oleg.Bulychov $
#pragma once

#include <string>
#include "src/heo/include/transmit.h"
//__________________________________________________________________________________
//__________________________________________________________________________________
template<class V>
struct transmit_handler<std::string, V>
{
    static void visit(std::string& s, V& v)
    {
        visit(s, v, meta::int2type<V::transmit_tag>());
    }

    static void visit(std::string& s, V& bcast, meta::int2type<BCAST_TAG>)
    {
        if (bcast.is_Root())
        {
            visit(s, bcast, meta::int2type<SEND_TAG>());
        }
        else
        {
            visit(s, bcast, meta::int2type<RECV_TAG>());
        }
    }

    static void visit(std::string& s, V& send, meta::int2type<SEND_TAG>)
    {
        size_t len = s.length();
        send << len;
        if (len > 0)
            send.visit_Array(const_cast<char*>(s.c_str()), len, "", 0);
    }

    static void visit(std::string& s, V& recv, meta::int2type<RECV_TAG>)
    {
        size_t len = 0;
        recv >> len;
        s.resize(len);
        if (len > 0)
            recv.visit_Array(&s[0], len, "", 0);
        //:not 100% portable but fast (assume std::string isn't sparse)
        //:std::string will be required to have contiguous storage with the new c++0x standard
    }
};
//__________________________________________________________________________________
//__________________________________________________________________________________
//__________________________________________________________________________________
//EOF!
